package com.android.mediaremote;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BluetoothAdapter extends BaseAdapter 
{
	private List<PeripheriqueBluetooth> periph;
	LayoutInflater inflater;
	
	public BluetoothAdapter(Context context,List<PeripheriqueBluetooth> periph)
	{
		inflater = LayoutInflater.from(context);
		this.periph=periph;
	}

	@Override
	public int getCount() 
	{
		return this.periph.size();
	}

	@Override
	public Object getItem(int position) 
	{
		return this.periph.get(position);
	}

	@Override
	public long getItemId(int position) 
	{
		return position;
	}

	private class ViewHolder
	{
		TextView nom;
		TextView adresse;
	}
	
	@Override

	public View getView(int position, View convertView, ViewGroup parent) 
	{
		ViewHolder holder;
		if(convertView == null) 
		{
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.periphbluetooth, null);
			holder.nom = (TextView)convertView.findViewById(R.id.nom);
			holder.adresse = (TextView)convertView.findViewById(R.id.adresse);
			convertView.setTag(holder);
		} 
		else 
		{
			holder = (ViewHolder) convertView.getTag();
		}
	
		holder.nom.setText(periph.get(position).getNom());
		holder.adresse.setText(periph.get(position).getAdresse());
	
		return convertView;
	}

}
